﻿namespace SLClient.CustomerControls
{
    using SLClient.Extension;
    using SLClient.Infrastructure;
    using SLClient.ServiceAPI;
    using System;
    using System.Linq.Expressions;
    using System.Reflection;
    using System.Windows;

    public class OrderWindowViewModel : ViewModelBase
    {
        private Visibility _loadingVisibity;
        private ViwUserPlayInfo _selectUserPlayInfo;

        public OrderWindowViewModel(ViwUserPlayInfo viwUserPlayInfo)
        {
            this._loadingVisibity =Visibility.Collapsed;
            this._selectUserPlayInfo = viwUserPlayInfo;
        }

        public OrderWindowViewModel(int orderId)
        {
            this._loadingVisibity = Visibility.Visible;
            this._selectUserPlayInfo = new ViwUserPlayInfo();
            this.Init(orderId);
        }

        public void Init(int orderId)
        {
            ServiceClient instance = WCFServicesUtil<ServiceClient>.GetInstance(ServiceType.ServiceAPI);
            instance.GetOrderDetailesCompleted += delegate (object obj, GetOrderDetailesCompletedEventArgs arg) {
                this.SelectUserPlayInfo = arg.Result;
                this.LoadingVisibity = Visibility.Collapsed;
            };
            instance.GetOrderDetailesAsync(orderId, true);
        }

        public string FianDian
        {
            get
            {
                decimal? fiandian = this._selectUserPlayInfo.Fiandian;
                return (string.Format("{0:F2}", fiandian.HasValue ? new decimal?(fiandian.GetValueOrDefault() * 100M) : null) + "% " + string.Format("{0:F2}", (this._selectUserPlayInfo.BetAmount * this._selectUserPlayInfo.DanBeiMoney) * this._selectUserPlayInfo.Fiandian));
            }
        }

        public Visibility LoadingVisibity
        {
            get
            {
                return this._loadingVisibity;
            }
            set
            {
                this._loadingVisibity = value;
                base.Notify<Visibility>(() => this.LoadingVisibity);
                //base.Notify<Visibility>(System.Linq.Expressions.Expression.Lambda<Func<Visibility>>(System.Linq.Expressions.Expression.Property(System.Linq.Expressions.Expression.Constant(this, typeof(OrderWindowViewModel)), (MethodInfo)(OrderWindowViewModel.get_LoadingVisibity)), new ParameterExpression[0]));
            }
        }

        public string Orization
        {
            get
            {
                return (this._selectUserPlayInfo.Orization ? "正向" : "逆向");
            }
        }

        public decimal? Scale
        {
            get
            {
                return (this._selectUserPlayInfo.JiangJin / 2M);
            }
        }

        public ViwUserPlayInfo SelectUserPlayInfo
        {
            get
            {
                return this._selectUserPlayInfo;
            }
            set
            {
                this._selectUserPlayInfo = value;
                base.Notify<ViwUserPlayInfo>(() => this.SelectUserPlayInfo);
                //base.Notify<ViwUserPlayInfo>(System.Linq.Expressions.Expression.Lambda<Func<ViwUserPlayInfo>>(System.Linq.Expressions.Expression.Property(System.Linq.Expressions.Expression.Constant(this, typeof(OrderWindowViewModel)), (MethodInfo)(OrderWindowViewModel.get_SelectUserPlayInfo)), new ParameterExpression[0]));
            }
        }
    }
}

